﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using EnvDTE;
using EnvDTE80;

namespace VSAddInFramework
{
    // Base class for VS AddIn commands, client need to inherit from this class and override necessary methods
    public abstract class VSCommand
    {
        public VSCommand(string name, string buttonText, string toolTip, bool msoButton, object bitmap, int commandStatsValue, 
            int commandStyleFlags, vsCommandControlType controlType)
        {
            m_Name = name;
            m_ButtonText = buttonText;
            m_ToolTip = toolTip;
            m_MSOButton = msoButton;
            m_Bitmap = bitmap;
            m_CommandStatsValue = commandStatsValue;
            m_CommandStyleFlags = commandStyleFlags;
            m_ControlType = controlType;

            m_InternalName = VSAddInMgr.Instance.ProgID + "." + this.Name;

        }
        public void Execute()
        {
            bool bSucceeded = this._Execute();
            Debug.Assert(bSucceeded);
        }
        public void QueryStatus(ref vsCommandStatus status)
        {
            _QueryStatus(ref status);
        }

        // Concrete command needs to override following methods
        public abstract bool _Execute();
        public virtual void _QueryStatus(ref vsCommandStatus status)
        {
            status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
        }
        public virtual void CreateCommandUI() { }
        public virtual void DestoryCommandUI() { }

        // Properties
        public string Name
        {
            get { return m_Name; }
        }
        public string ButtonText
        {
            get { return m_ButtonText; }
        }
        public string ToolTip
        {
            get { return m_ToolTip; }
        }
        public bool MSOButton
        {
            get { return m_MSOButton; }
        }
        public object Bitmap
        {
            get { return m_Bitmap; }
        }
        public int CommandStatsValue
        {
            get { return m_CommandStatsValue; }
        }
        public int CommandStyleFlags
        {
            get { return m_CommandStyleFlags; }
        }
        public vsCommandControlType ControlType
        {
            get { return m_ControlType; }
        }
        public string InternalName
        {
            get
            {
                return m_InternalName;
            }
        }
        public Command InternalCommand
        {
            get { return m_InternalCommand; }
            set { m_InternalCommand = value; }
        }

        public static object[] contextGUIDS = new object[] { };

        // Data members
        private string m_Name;
        private string m_ButtonText;
        private string m_ToolTip;
        private bool m_MSOButton;
        private object m_Bitmap;
        private int m_CommandStatsValue;
        private int m_CommandStyleFlags;
        private vsCommandControlType m_ControlType;
        private string m_InternalName;

        // The Visual Studio command object
        Command m_InternalCommand;
        
    }
}
